namespace Launcher

import System

def SplitText(text as string, minLen as int):
	sb = System.Text.StringBuilder()
	line = ""
	words = text.Split(char(' '))
	for w in words:
		line += w
		if len(line) > minLen:
			sb.Append(line)
			sb.Append("\n")
			line = ""
		else:
			line += " "
			
	return sb.ToString().Trim()

def Distance(x1 as int, y1 as int, x2 as int, y2 as int):
	dx = x1 - x2
	dy = y1 - y2
	
	return cast(int, Math.Sqrt(dx**2 + dy**2))

def Interpolate(start as int, end as int, fraction as single):
	return start + cast(int, (end - start) * fraction)

[extension]
def Max(n as int, v as int) as int:
	return (n if n > v else v)

[extension]
def Min(n as int, v as int) as int:
	return (n if n < v else v)

[extension]
def Each(e as System.Collections.IEnumerable, action as callable(object)):
	for item in e:
		action(item)

[extension]
def Enumerate(e as System.Collections.IEnumerable, action as callable(int, object)):
	for i as int, item in enumerate(e):
		action(i, item)
